//package icu.xuyijie.springbootlearning2.chapter6;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.security.core.GrantedAuthority;
//import org.springframework.security.core.authority.SimpleGrantedAuthority;
//import org.springframework.security.core.userdetails.User;
//import org.springframework.security.core.userdetails.UserDetails;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.core.userdetails.UsernameNotFoundException;
//import org.springframework.security.crypto.password.PasswordEncoder;
//import org.springframework.stereotype.Service;
//
//import java.util.ArrayList;
//import java.util.List;
//
///**
// * @author 徐一杰
// * @date 2025/03/11 13:46
// * @description 这里可以从数据库取真实数据
// */
//@Service
//public class MyUserDetailsService implements UserDetailsService {
//    @Autowired
//    private PasswordEncoder passwordEncoder;
//
//    @Override
//    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
//        // 通过用户名从数据库获取用户信息，略
//        // User user = mapper.findUser()
//
//        // 角色和权限列表，下面两种写法都行
//        List<GrantedAuthority> authorityList = new ArrayList<>();
//        // 角色必须以ROLE_开头，security在判断角色时会自动截取ROLE_
//        authorityList.add(new SimpleGrantedAuthority("ROLE_" + "user"));
//        //不以ROLE_开头的加进去是权限
//        authorityList.add(new SimpleGrantedAuthority("select"));
//        authorityList.add(() -> "delete");
//
//
//        //登录成功时，把用户信息保存到security
//        return new User(
//                username,
//                // 数据库应该存的是使用passwordEncoder加密后的密码，所以这里加密一下明文给security比对
//                passwordEncoder.encode("123456"),
//                authorityList
//        );
//    }
//}
